package com.waterflow.xanner.model;

import android.content.Context;

public class LevelManager {
	
	private static final String SOLUTIONS_SEPARATOR = ",";

	private LevelInfo[] levels;

	public static class LevelInfo {
		String name;
		public String str;
		public int duration;
		String[] solutions;
	}

	public LevelManager(Context context) {
		String[] levelNames = context.getResources().getStringArray(
				context.getResources().getIdentifier("list_of_levels", "array",
						context.getPackageName()));

		levels = new LevelInfo[levelNames.length];
		for (int i = 0; i < levelNames.length; i++) {
			levels[i] = new LevelInfo();

			String[] args = context.getResources().getStringArray(
					context.getResources().getIdentifier(levelNames[i],
							"array", context.getPackageName()));

			levels[i].name = levelNames[i];
			levels[i].str = args[0];
			levels[i].duration = Integer.parseInt(args[1]);
			levels[i].solutions = args[2].split(SOLUTIONS_SEPARATOR);
			for(int j=0;j<levels[i].solutions.length;j++){
				levels[i].solutions[j] = levels[i].solutions[j].trim();
			}
		}
	}

	public boolean hasLevel(int i) {
		return (i>=0)&&(i<levels.length);
	}

	public LevelInfo get(int level) {
		return levels[level];
	}
	
	public boolean isSolution(int level, String answer){
		for(String solution:levels[level].solutions){
			if(answer.equalsIgnoreCase(solution)){
				return true;
			}
		}
		return false;
	}
}
